'''
ship asrie
    attribute
        foo bar
    gun-port laser
    gun-port laser
ship beast

read line 1: {ship: asrie}
read line 2: 
    ship: {
        __value: 'asrie',
        attribute: None
    }
read line 3:
    ship: {
        __value: 'asrie',
        attribute: {
            __value: None # this will be ignored
            foo: bar
        }
    }
read line 5:
    ship: {
        __value: 'asrie',
        attribute: {
            foo: bar
        }
        gun-port: laser
read line 6:
    ship: {
        __value: 'asrie',
        attribute: {
            foo: bar
        }
        gun-port: [laser, laser]
read line 7:
    ship: [{
        __value: 'asrie',
        attribute: {
            foo: bar
        }
        gun-port: [laser, laser]
    }, {
        __value: beast
    }]
'''

class Node(list):
    '''
    node_name node_value
    - Node child node 1
    - Node child node 2
    '''

    def __init__(self, key, val):
        self.__key = key
        self.__value = val

    Key = property(lambda self: self.__key)

    def set_value(self, value):
        self.__value = value
    Value = property(lambda self: self.__value, set_value)

class THead(list):

    def __init__(self, content):
        self._content = content
        self._x = None
        self._y = None
        self._row_index = None

    def set_content(self, value):
        self._content = value
    Content = property(lambda self: self._content, set_content)
    X = property(lambda self: self._x)
    Y = property(lambda self: self._y)
    RowIndex = property(lambda self: self._row_index)

    def get_span(self):
        i = 1
        for ele in self:
            i = i + ele.get_span()
        return i
    
    def append_sub(self, content):
        for ele in self:
            if content == ele.Content:
                return ele
        retn = THead(content)
        self.append(retn)
        return retn

    def reindex(self, x, y):
        self._x = x
        self._y = y
        y = y + 1
        for ele in self:
            ele.reindex(x + 1, y)
            x = x + ele.get_span()
